package practice.phase03.module01.mapreduce.playtime;

import org.apache.hadoop.io.Writable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class PlayLogBean implements Writable {
    private String deviceId;
    private Long selfDuration;
    private Long thirdDuration;
    private Long totalDuration;

    public PlayLogBean() {
    }

    public PlayLogBean(String deviceId, Long selfDuration, Long thirdDuration) {
        this.deviceId = deviceId;
        this.selfDuration = selfDuration;
        this.thirdDuration = thirdDuration;
        this.totalDuration = selfDuration + thirdDuration;
    }

    @Override
    public void write(DataOutput out) throws IOException {
        out.writeUTF(deviceId);
        out.writeLong(selfDuration);
        out.writeLong(thirdDuration);
        out.writeLong(totalDuration);
    }

    @Override
    public void readFields(DataInput in) throws IOException {
        deviceId = in.readUTF();
        selfDuration = in.readLong();
        thirdDuration = in.readLong();
        totalDuration = in.readLong();
    }

    public String getDeviceId() {
        return deviceId;
    }

    public void setDeviceId(String deviceId) {
        this.deviceId = deviceId;
    }

    public Long getSelfDuration() {
        return selfDuration;
    }

    public void setSelfDuration(Long selfDuration) {
        this.selfDuration = selfDuration;
    }

    public Long getThirdDuration() {
        return thirdDuration;
    }

    public void setThirdDuration(Long thirdDuration) {
        this.thirdDuration = thirdDuration;
    }

    public Long getTotalDuration() {
        return totalDuration;
    }

    public void setTotalDuration(Long totalDuration) {
        this.totalDuration = totalDuration;
    }

    @Override
    public String toString() {
        return deviceId +
                "\t" + selfDuration +
                "\t" + thirdDuration +
                "\t" + totalDuration;
    }
}
